<!DOCTYPE html>
<html>
{include file="task/task_head"}
<body style="padding:10px;">
<div class="tplay-body-div">
    {include file="task/task_tab"}
    <div style="margin-top: 20px;">
    </div>

    <form class="layui-form" id="admin">
        <div class="layui-form-item">
            <label class="layui-form-label">任务名称</label>
            <div class="layui-input-inline">
                <input name="task_name" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" type="text" {notempty name="$info.task_name"}value="{$info.task_name}"{/notempty}>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">任务类型</label>
            <div class="layui-input-inline">
                <select name="task_type" lay-verify="required" lay-search="">
                    <option value="">请选择</option>
                    {volist name="taskTypeName" id="vo"}
                    <option value="{$key}" {notempty name="$info.task_type"}{eq name="$info.task_type" value="$key"} selected=""{/eq}{/notempty}>{$vo}</option>
                    {/volist}
                    </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">开始时间</label>
            <div class="layui-input-inline">
                <input name="begin_time" id="begin_time" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" type="text" {notempty name="$info.begin_time"} value="{$info.begin_time|date='Y-m-d',###}"{/notempty}>
            </div>
            <label class="layui-form-label">结束时间</label>
            <div class="layui-input-inline">
                <input name="end_time" id="end_time"  lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" type="text" {notempty name="$info.end_time"} value="{$info.end_time|date='Y-m-d',###}"{/notempty}>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">人员</label>
            <div class="layui-collapse layui-input-inline person-list" lay-accordion="">
                {volist name="presonRoleList" id="presonRole"}
                <div class="layui-colla-item" style="">
                    <h2 class="layui-colla-title" style="background:0;">{$presonRole.name}</h2>
                    <div class="layui-colla-content">
                        <table>
                            <tbody>
                            {volist name="presonRole.person_list" id="person"}
                            <tr>
                                <td>
                                    <input type="checkbox" lay-verify="otherReq"  class="otherReq" lay-ignore lay-skin="primary" name="personId[]" value="{$person.admin_id}" <?php echo in_array($person['admin_id'], $personIds)?'checked="checked"':'' ?> > {$person.admin_name}
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                        </table>
                    </div>
                </div>
                {/volist}
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-inline">
                <select name="task_status" lay-verify="required" lay-search="" >
                    <option value="">请选择</option>
                    {volist name="taskStatusMap" id="task_status"}
                    <option value="{$key}" {notempty name="$info.task_status"}{eq name="$info.task_status" value="$key"} selected=""{/eq}{/notempty}>{$task_status}</option>
                    {/volist}
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <textarea placeholder="项目描述" class="layui-textarea" name="task_content" style="width: 500px;">{notempty name="$info.task_content"}{$info.task_content}{/notempty}</textarea>
            </div>
        </div>
        {notempty name="$info"}
        <input type="hidden" name="task_id" value="{$info.task_id}">
        {/notempty}
        <input type="hidden" name="project_id" value="{$project_id}">

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="admin">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>

    </form>


    {include file="public/foot"}
    <script>
        layui.use(['layer', 'form'], function() {
            var layer = layui.layer,
                $ = layui.jquery,
                form = layui.form;
            $(window).on('load', function() {
                form.on('submit(admin)', function(data) {
                    $.ajax({
                        url:"{:url('admin/task/publish')}",
                        data:$('#admin').serialize(),
                        type:'post',
                        async: false,
                        success:function(res) {
                            if(res.code == 1) {
                                // layer.alert(res.msg, function(index){
                                    location.href = res.url;
                                // })
                            } else {
                                layer.msg(res.msg);
                            }
                        },
                        error: function(err) {
                            console.log('err', err)
                        }
                    })
                    return false;
                });
            });
        });
    </script>

    <script>
        var min_end_time = '',
            max_begin_time = '';
        layui.use(['laydate','form'], function(){
            var laydate = layui.laydate;
            laydate.render({
                trigger: 'click',
                elem: '#begin_time'
                ,done: function(value, date){
                    min_end_time = value;
                    dateDestroy('end_time');
                    initEndDate();
                }
            });

            laydate.render({
                trigger: 'click',
                elem: '#end_time'
                ,done: function(value, date){
                    max_begin_time = value;
                    dateDestroy('begin_time');
                    initBeginDate();
                }
            });

            var form = layui.form;
            otherVerify(form, '人员必填不能为空')

        });
        //初始化开始时间插件
        function initBeginDate() {
            console.info('初始化开始时间');
            const laydate = layui.laydate;
            laydate.render({
                trigger: 'click',
                elem: '#begin_time'
                ,max: max_begin_time
                ,done: function(value, date){
                    min_end_time = value;
                    console.info('最小结束时间', min_end_time);
                    dateDestroy('end_time');
                    console.info('销毁结束时间');
                    initEndDate();
                }
            });
        }
        //初始化结束时间插件
        function initEndDate() {
            console.info('初始化结束时间');
            const laydate = layui.laydate;
            laydate.render({
                trigger: 'click',
                elem: '#end_time'
                ,min: min_end_time
                ,done: function(value, date){
                    max_begin_time = value;
                    console.info('最大开始时间', max_begin_time);
                    dateDestroy('begin_time');
                    console.info('销毁开始时间');
                    initBeginDate();
                }
            });
        }

        //销毁时间
        function dateDestroy(id){
            var inputDate = $("#"+id).clone(true);
            $(inputDate).removeAttr("lay-key");
            $("#"+id).after(inputDate);
            $("#"+id).remove();
        }

    </script>
    {include file="common/otherVerify"}
</div>
</body>
</html>